<template>
		<view class="enter-type">
			<NavBar title="入驻申请" color="#fff" bgc="transparent"/>
			<view class="btn-box">
				<view class="btn" @tap="tapEnter(2)" :style="{width:w, height:h}"> 企业入驻商户 </view>
				<view class="btn" @tap="tapEnter(1)" :style="{width:w, height:h}"> 个人入驻商户 </view>
			</view>
		</view>
</template>

<script setup>
	import { computed, ref } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import NavBar from '@/components/NavBar.vue'
	import { GetEnterShopApi } from '@/service/index.js'
	import { useUserStore, useMiddleWare } from '@/store/index.js'
	const { safeArea } = uni.getSystemInfoSync()
	const emit = defineEmits(['tapEnter'])
	const popupRef = ref()
	const w = computed(() => (safeArea.width / 375) * 241 +'px' )
	const h = computed(() => (safeArea.width / 375) * 50 +'px' )
	const tapEnter = (type) => {
		uni.redirectTo({
			url: `/pages/shopPages/enterShop/enterShop?type=${type}`
		})
	}
	const isShop = () => {
		const { GETUSERINFO } = useUserStore()
		GetEnterShopApi().then(res => {
			// 'checked'=>已审核,'review'=>审核中,'reject'=>已驳回
			if(res == null) return
			if (res.status == 'checked') {
				GETUSERINFO()
				uni.redirectTo({ url: '/pages/shopPages/shopHome/shopHome' })
			} else if (res.status == 'review') {
				const title = '入驻申请'
				const navParams = {
					title: '报名信息提交成功',
					tips: '报名信息提交成功，平台收到信息会在5个工作日内更您核实信息，请耐心等待！'
				}
				uni.redirectTo({
					url: `/pages/auditStatus/auditStatus?title=${title}&params=${JSON.stringify(navParams)}`
				})
			} else if (res.status == 'reject') {
				const title = '入驻申请未通过'
				const navParams = {
					tips: '您可能信息提交有误，可以联系您当地的代理商！ 也可以编辑信息后继续提交审核！',
					imgType: 'error',
					errText: res.reject_reason,
					cancelText: '返回首页',
					submitText: '编辑信息'
				}
				uni.redirectTo({
					url: `/pages/auditStatus/auditStatus?title=${title}&params=${JSON.stringify(navParams)}`
				})
			}
		})
	}
	onLoad((e) => {
		const { tid, shop } = e
		const { SETTID } = useMiddleWare()
		if(tid) SETTID(tid)
		if(!shop) isShop()
	})
</script>

<style lang="scss" scoped>
	.enter-type {
		background: url('/static/icon/bg.png') no-repeat center center;
		background-size: 100% 100%;
		width: 750rpx;
		aspect-ratio: .46;
		.btn-box {
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%, 50%);
		}
		.btn {
			display: flex;
			justify-content: center;
			align-items: center;
			background: #FF3B1E;
			border-radius: 99px;
			margin-top: 40px;
			font-weight: 500;
			font-size: 18px;
			color: #FFFFFF;
			&:nth-of-type(1) {
				margin-top: 0;
			}
		}
	}
</style>